package com.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * 工具类
 */
public class SystemUtil {

    /**
     * 打印功能位置提示
     * @param title
     */
    public static void functionTitle(String title){
        System.out.println("\n>>> " + title + "\n");
    }

    /**
     * 系统错误i提示
     * @param massage
     */
    public static void error(String massage){
        System.err.println("系统提示：" + massage + "\n");
    }

    /**
     * 获取自定内容提示的字符串输入
     * @param keyword
     * @return
     */
    public static String inputString(String keyword, boolean userDefault){
        //获取扫描器
        Scanner scanner = new Scanner(System.in);
        //判断，是否使用默认格式
        if (userDefault){
            //默认输入提示
            System.out.print("请输入" + keyword + ": ");
        }else{
            System.out.print(keyword + ": ");
        }
        //返回输入内容
        return scanner.next();
    }

    /**
     * 获取默认提示的字符串输入
     * @param keyword
     * @return
     */
    public static String inputString(String keyword){
        return inputString(keyword, true);
    }

    /**
     * 获取自定内容提示的整数输入
     * @param keyword
     * @return
     */
    public static Integer inputInt(String keyword, boolean userDefault){
        return Integer.parseInt(inputString(keyword, userDefault));
    }

    /**
     * 获取默认内容提示的整数输入
     * @param keyword
     * @return
     */
    public static Integer inputInt(String keyword){
        return Integer.parseInt(inputString(keyword, true));
    }

    /**
     * 获取自定内容提示的小数输入
     * @param keyword
     * @return
     */
    public static Double inputDouble(String keyword, boolean userDefault){
        return Double.parseDouble(inputString(keyword, userDefault));
    }

    /**
     * 获取默认内容提示的小数输入
     * @param keyword
     * @return
     */
    public static Double inputDouble(String keyword){
        return Double.parseDouble(inputString(keyword, true));
    }

    /**
     * 日期格式化
     * @param date
     * @return
     */
    public static Date dateFormat(String date){
        /* 日期处理 */
        String week = date.substring(0,3);
        String mon = date.substring(4,7);
//        System.out.println(week);
//        System.out.println(mon);
        //匹配
        switch (week){
            case "Mon":
                date = date.replace(week, "星期一");
                break;
            case "Tue":
                date = date.replace(week, "星期二");
                break;
            case "Wed":
                date = date.replace(week, "星期三");
                break;
            case "Thu":
                date = date.replace(week, "星期四");
                break;
            case "Fri":
                date = date.replace(week, "星期五");
                break;
            case "Sat":
                date = date.replace(week, "星期六");
                break;
            case "Sun":
                date = date.replace(week, "星期日");
                break;
        }
        switch (mon){
            case "Jan":
                date = date.replace(mon, "一月");
                break;
            case "Feb":
                date = date.replace(mon, "二月");
                break;
            case "Mar":
                date = date.replace(mon, "三月");
                break;
            case "Apr":
                date = date.replace(mon, "四月");
                break;
            case "May":
                date = date.replace(mon, "五月");
                break;
            case "Jun":
                date = date.replace(mon, "六月");
                break;
            case "Jul":
                date = date.replace(mon, "七月");
                break;
            case "Aug":
                date = date.replace(mon, "八月");
                break;
            case "Sep":
                date = date.replace(mon, "九月");
                break;
            case "Oct":
                date = date.replace(mon, "十月");
                break;
            case "Nov":
                date = date.replace(mon, "十一月");
                break;
            case "Dec":
                date = date.replace(mon, "十二月");
                break;
        }
//        System.out.println(date);

        SimpleDateFormat sdf1 = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            String format = sdf2.format(sdf1.parse(date));
            System.out.println(format);
            return sdf2.parse(format);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }



    public static void main(String[] args) {
        System.out.println(dateFormat("星期日 一月 21 11:44:51 CST 2021"));
        System.out.println(dateFormat("Sun Nov 21 11:51:22 CST 2021"));
        System.out.println(new Date());
    }


}
